package company.qianxing_F;

public class Qi3 {

    public static void main(String[] args) {
        System.out.println(Qi3.getCount(new int[]{2, 1, 2, 1, 1, 1}));
    }

    private static int getCount(int[] nums) {
        int length = nums.length;
        int minIndex = 0;
        for (int i = 0; i < length; i++) {
            if (nums[i] < nums[minIndex])
                minIndex = i;
        }
        int sum = 1;
        int i = minIndex - 1;
        int lastNum = 1;
        while (i >= 0) {
            if (nums[i] > nums[i + 1]) {
                lastNum++;
                sum += lastNum;
            } else {
                lastNum = 1;
                sum += 1;
            }
            i--;
        }
        int j = minIndex + 1;
        lastNum = 1;
        while (j < length) {
            if (nums[j] > nums[j - 1]) {
                lastNum++;
                sum += lastNum;
            } else {
                lastNum = 1;
                sum += 1;
            }
            j++;
        }
        return sum;
    }
}
